#include<bits/stdc++.h>
using namespace std;
namespace fastio
{
    const int bufl=1<<20;
    const double base1[16]={1,1e-1,1e-2,1e-3,1e-4,1e-5,1e-6,1e-7,1e-8,1e-9,1e-10,1e-11,1e-12,1e-13,1e-14,1e-15};
    const double base2[16]={1,1e1,1e2,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13,1e14,1e15};
    struct IN{
        FILE *IT;char ibuf[bufl],*is=ibuf,*it=ibuf;
        IN(){IT=stdin;}IN(char *a){IT=fopen(a,"r");}
        inline char getChar(){if(is==it){it=(is=ibuf)+fread(ibuf,1,bufl,IT);if(is==it)return EOF;}return *is++;}
        template<typename Temp>inline void getInt(Temp &a){a=0;int b=0,c=getChar();while(c<48||c>57)b^=(c==45),c=getChar();while(c>=48&&c<=57)a=(a<<1)+(a<<3)+c-48,c=getChar();if(b)a=-a;}
        template<typename Temp>inline void getDouble(Temp &a){a=0;int b=0,c=getChar(),d=0;__int128 e=0,f=0;while(c<48||c>57)b^=(c==45),c=getChar();while(c>=48&&c<=57)e=(e<<1)+(e<<3)+c-48,c=getChar();if(c==46){c=getChar();while(c>=48&&c<=57)d++,f=(f<<1)+(f<<3)+c-48,c=getChar();}a=e+base1[d]*f;if(b)a=-a;}
        IN& operator>>(char &a){a=getChar();return *this;}
        IN& operator>>(char *a){do{*a=getChar();}while(*a<=32);while(*a>32)*++a=getChar();*a=0;return *this;}
        IN& operator>>(string &a){char b=getChar();while(b<=32)b=getChar();while(b>32)a+=b,b=getChar();return *this;}
        IN& operator>>(int &a){getInt(a);return *this;}
        IN& operator>>(long long &a){getInt(a);return *this;}
        IN& operator>>(__int128 &a){getInt(a);return *this;}
        IN& operator>>(float &a){getDouble(a);return *this;}
        IN& operator>>(double &a){getDouble(a);return *this;}
        IN& operator>>(long double &a){getDouble(a);return *this;}
    };
    struct OUT{
        FILE *IT;char obuf[bufl],*os=obuf,*ot=obuf+bufl;int Eps;long double Acc;
        OUT(){IT=stdout,Eps=6,Acc=1e-6;}OUT(char *a){IT=fopen(a,"w"),Eps=6,Acc=1e-6;}
        inline void ChangEps(int x=6){Eps=x;}
        inline void flush(){fwrite(obuf,1,os-obuf,IT);os=obuf;}
        inline void putChar(int a){*os++=a;if(os==ot)flush();}
        template<typename Temp>inline void putInt(Temp a){if(a<0){putChar(45);a=-a;}if(a<10){putChar(a+48);return;}putInt(a/10);putChar(a%10+48);}
        template<typename Temp>inline void putLeading(Temp a,int b){if(!b)return;putLeading(a/10,b-1);putChar(a%10+48);}
        template<typename Temp>inline void putDouble(Temp a){if(a<0){putChar(45);a=-a;}__int128 b=a;putInt(b);a-=b;a*=base2[Eps];b=a+Acc;putChar(46);putLeading(b,Eps);}
        OUT& operator<<(char a){putChar(a);return *this;}
        OUT& operator<<(char *a){while(*a>32)putChar(*a++);return *this;}
        OUT& operator<<(string a){for(auto c:a)putChar(c);return *this;}
        OUT& operator<<(int a){putInt(a);return *this;}
        OUT& operator<<(long long a){putInt(a);return *this;}
        OUT& operator<<(__int128 a){putInt(a);return *this;}
        OUT& operator<<(float a){putDouble(a);return *this;}
        OUT& operator<<(double a){putDouble(a);return *this;}
        OUT& operator<<(long double a){putDouble(a);return *this;}
        ~OUT(){flush();}
    };
}
using fastio::IN;
using fastio::OUT;
IN fin;
OUT fout;
const int NN=3004,P=1e9+7,dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
int d[NN][NN],n;
char s[NN][NN];
bool chk(int x,int y)
{
	return x>=1&&x<=n&&y>=1&&y<=n;
}
int main()
{
	freopen("brick.in","r",stdin);
	freopen("brick.out","w",stdout);
	int K;
	fin>>n>>K;
	memset(d,0x3f,sizeof(d));
	queue<pair<int,int> >q;
	for(int i=1;i<=n;i++)
	{
		fin>>(s[i]+1);
		for(int j=1;j<=n;j++)
			if(s[i][j]=='#')
			{
				q.push({i,j});
				d[i][j]=0;
			}
	}
	while(q.size())
	{
		int x=q.front().first,y=q.front().second;
		q.pop();
		for(int i=0;i<4;i++)
		{
			int nx=x+dx[i],ny=y+dy[i];
			if(!chk(nx,ny))
				continue;
			if(d[nx][ny]>d[x][y]+1)
			{
				d[nx][ny]=d[x][y]+1;
				q.push({nx,ny});
			}
		}
	}
	if(K==1)
	{
		int ans=0;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				if(d[i][j]==1)
					ans++;
		printf("%d",ans);
		return 0;
	}
	if(K==2)
	{
		int cnt=0,ans=0;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				if(d[i][j]==1)
				{
					cnt++;
					for(int k=0;k<4;k++)
					{
						int ni=i+dx[k],nj=j+dy[k];
						if(d[ni][nj]==2)
							ans=(ans+1)%P;
					}
				}
		ans=(ans+1ll*cnt*(cnt-1)/2%P);
		printf("%d",ans);
		return 0;
	}
	if(K==3)
	{
		int cnt=0,ans=0;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				if(d[i][j]==1)
				{
					cnt++;
					int cnt2=0;
					for(int k=0;k<4;k++)
					{
						int ni=i+dx[k],nj=j+dy[k];
						if(d[ni][nj]==2)
						{
							cnt2++;
							for(int l=0;l<4;l++)
							{
								int nni=ni+dx[l],nnj=nj+dy[l];
								if(chk(nni,nnj)&&d[nni][nnj]!=1)
									ans=(ans+1)%P;
							}
						}
					}
					ans=(ans+cnt2*(cnt2-1)/2)%P;
				}
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				if(d[i][j]==2)
				{
					int cnt1=0;
					for(int k=0;k<4;k++)
					{
						int ni=i+dx[k],nj=j+dy[k];
						if(d[ni][nj]==1)
							cnt1++;
					}
					ans=(ans+1ll*cnt*(cnt-1)/2%P-1ll*(cnt-cnt1)*(cnt-cnt1-1)/2%P+P)%P;
				}
		ans=(ans+(__int128)cnt*(cnt-1)*(cnt-2)/6%P)%P;
		printf("%d",ans);
		return 0;
	}
	if(K==4)
	{
		int cnt=0,ans=0;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				if(d[i][j]==1)
				{
					cnt++;
					int cnt2=0;
					for(int k=0;k<4;k++)
					{
						int ni=i+dx[k],nj=j+dy[k];
						if(d[ni][nj]==2)
						{
							cnt2++;
							int cnt3=0;
							for(int l=0;l<4;l++)
							{
								int nni=ni+dx[l],nnj=nj+dy[l];
								if(chk(nni,nnj)&&d[nni][nnj]!=1)
								{
									cnt3++;
									for(int r=0;r<4;r++)
									{
										int nnni=nni+dx[r],nnnj=nnj+dy[r];
										if(abs(nnni-i)+abs(nnnj-j)==3&&chk(nnni,nnnj)&&d[nnni][nnnj]!=1)
											ans=(ans+1)%P;
									}
								}
							}
							ans=(ans+cnt3*(cnt3-1)/2)%P;
						}
					}
					ans=(ans+cnt2*(cnt2-1)*(cnt2-2)/6)%P;
					for(int k=0;k<4;k++)
						for(int l=k+1;l<4;l++)
						{
							int ni1=i+dx[k],nj1=j+dy[k],ni2=i+dx[l],nj2=j+dy[l];
							if(d[ni1][nj1]==2&&d[ni2][nj2]==2)
							{
								int cnt3=0;
								for(int r=0;r<4;r++)
								{
									int nni=ni1+dx[r],nnj=nj1+dy[r];
									if(chk(nni,nnj)&&d[nni][nnj]!=1)
										cnt3++;
								}
								for(int r=0;r<4;r++)
								{
									int nni=ni2+dx[r],nnj=nj2+dy[r];
									if(chk(nni,nnj)&&d[nni][nnj]!=1)
										cnt3++;
								}
								for(int r=0;r<4;r++)
								{
									int nni=ni1+dx[r],nnj=nj1+dy[r];
									if(chk(nni,nnj)&&d[nni][nnj]!=1&&abs(nni-ni2)+abs(nnj-nj2)==1)
										cnt3--;
								}
								ans=(ans+cnt3)%P;
							}
						}
				}
		int cnt21=0;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
			{
				if(d[i][j]==3)
					for(int k=0;k<4;k++)
					{
						int ni=i+dx[k],nj=j+dy[k],cnt1=0;
						if(d[ni][nj]==2)
						{
							for(int l=0;l<4;l++)
							{
								int nni=ni+dx[l],nnj=nj+dy[l];
								if(d[nni][nnj]==1)
									cnt1++;
							}
							ans=(ans+1ll*cnt*(cnt-1)/2%P-1ll*(cnt-cnt1)*(cnt-cnt1-1)/2%P+P)%P;
						}
					}
				if(d[i][j]==2)
				{
					int cnt1=0,cnt2=0;
					for(int k=0;k<4;k++)
					{
						int ni=i+dx[k],nj=j+dy[k];
						if(d[ni][nj]==1)
							cnt1++;
						if(d[ni][nj]==2)
							cnt2++;
					}
					ans=(ans+(__int128)cnt*(cnt-1)*(cnt-2)/6%P-(__int128)(cnt-cnt1)*(cnt-cnt1-1)*(cnt-cnt1-2)/6%P+P)%P;
					ans=(ans+1ll*cnt1*cnt21%P)%P;
					cnt21=(cnt1+cnt21)%P;
					ans=(ans+cnt1*(cnt1-1)/2*cnt2)%P;
					for(int k=0;k<4;k++)
					{
						int ni=i+dx[k],nj=j+dy[k],cnt12=0;
						if(d[ni][nj]==2)
						{
							for(int l=0;l<4;l++)
							{
								int nni=ni+dx[l],nnj=nj+dy[l];
								if(d[nni][nnj]==1)
									cnt12++;
							}
							ans=(ans+cnt1*(cnt-cnt1-cnt12))%P;
						}
					}
				}
			}
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				if(d[i][j]==1)
				{
					if(d[i+1][j]==2&&d[i][j+1]==2&&d[i+1][j+1]==1)
						ans=(ans-1+P)%P;
					if(d[i][j-1]==2&&d[i+1][j]==2&&d[i+1][j-1]==1)
						ans=(ans-1+P)%P;
					for(int k=0;k<4;k++)
						for(int l=k+1;l<4;l++)
						{
							int ni1=i+dx[k],nj1=j+dy[k],ni2=i+dx[l],nj2=j+dy[l];
							if(d[ni1][nj1]==2&&d[ni2][nj2]==2)
							{
								int cnt1=0;
								for(int r=0;r<4;r++)
								{
									int nni=ni1+dx[r],nnj=nj1+dy[r];
									if(d[nni][nnj]==1)
										cnt1++;
								}
								for(int r=0;r<4;r++)
								{
									int nni=ni2+dx[r],nnj=nj2+dy[r];
									if(d[nni][nnj]==1)
										cnt1++;
								}
								for(int r=0;r<4;r++)
								{
									int nni=ni1+dx[r],nnj=nj1+dy[r];
									if(d[nni][nnj]==1&&abs(nni-ni2)+abs(nnj-nj2)==1)
										cnt1--;
								}
								ans=(ans+cnt-cnt1-1)%P;
							}
						}
				}
		ans=(ans+(__int128)cnt*(cnt-1)*(cnt-2)*(cnt-3)/24%P)%P;
		printf("%d",ans);
	}
	return 0;
}
